import 'package:winkai/generated/json/base/json_convert_content.dart';
import 'package:winkai/helper/iap/entity/g_iap_req.dart';

GIAPReq $GIAPReqFromJson(Map<String, dynamic> json) {
  final GIAPReq gIAPReq = GIAPReq();
  final String? deviceId = jsonConvert.convert<String>(json['device_id']);
  if (deviceId != null) {
    gIAPReq.deviceId = deviceId;
  }
  final String? packageName = jsonConvert.convert<String>(json['package_name']);
  if (packageName != null) {
    gIAPReq.packageName = packageName;
  }
  final String? productId = jsonConvert.convert<String>(json['product_id']);
  if (productId != null) {
    gIAPReq.productId = productId;
  }
  final int? quantity = jsonConvert.convert<int>(json['quantity']);
  if (quantity != null) {
    gIAPReq.quantity = quantity;
  }
  final int? purchaseTime = jsonConvert.convert<int>(json['purchase_time']);
  if (purchaseTime != null) {
    gIAPReq.purchaseTime = purchaseTime;
  }
  final int? purchaseState = jsonConvert.convert<int>(json['purchase_state']);
  if (purchaseState != null) {
    gIAPReq.purchaseState = purchaseState;
  }
  final String? purchaseToken = jsonConvert.convert<String>(
      json['purchase_token']);
  if (purchaseToken != null) {
    gIAPReq.purchaseToken = purchaseToken;
  }
  return gIAPReq;
}

Map<String, dynamic> $GIAPReqToJson(GIAPReq entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['device_id'] = entity.deviceId;
  data['package_name'] = entity.packageName;
  data['product_id'] = entity.productId;
  data['quantity'] = entity.quantity;
  data['purchase_time'] = entity.purchaseTime;
  data['purchase_state'] = entity.purchaseState;
  data['purchase_token'] = entity.purchaseToken;
  return data;
}

extension GIAPReqExtension on GIAPReq {
  GIAPReq copyWith({
    String? deviceId,
    String? packageName,
    String? productId,
    int? quantity,
    int? purchaseTime,
    int? purchaseState,
    String? purchaseToken,
  }) {
    return GIAPReq()
      ..deviceId = deviceId ?? this.deviceId
      ..packageName = packageName ?? this.packageName
      ..productId = productId ?? this.productId
      ..quantity = quantity ?? this.quantity
      ..purchaseTime = purchaseTime ?? this.purchaseTime
      ..purchaseState = purchaseState ?? this.purchaseState
      ..purchaseToken = purchaseToken ?? this.purchaseToken;
  }
}